﻿using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using Isuka.Automation;

namespace Isuka.Excel
{
    public abstract class ExcelObject
        : AutomationObject
    {
        readonly XApplication application;

        protected ExcelObject(XApplication application, object obj)
            : base(obj)
        {
            Contract.Requires<ArgumentNullException>(application != null, "application");
            Contract.Requires<ArgumentNullException>(obj != null, "obj");

            this.application = application;
            application.Container.Add(this);
        }

        public XApplication Application
        {
            get
            {
                Contract.Ensures(Contract.Result<XApplication>() != null);
                return application;
            }
        }
        
        #region ContractInvariantMethod

        [ContractInvariantMethod]
        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
        [DebuggerStepThrough]
        void ObjectInvariant()
        {
            Contract.Invariant(application != null);
        }

        #endregion
    }
}
